import cv2
import numpy as np


def flip(img_path):
    img = cv2.imread(img_path)

    # 水平镜像
    h_flip = cv2.flip(img, 1)
    cv2.imwrite(img_path.split('.jpg')[0] + 'h_flip.jpg', h_flip)

    # 垂直镜像
    v_flip = cv2.flip(img, 0)
    cv2.imwrite(img_path.split('.jpg')[0] + 'v_flip.jpg', v_flip)

    # 水平垂直镜像
    hv_flip = cv2.flip(img, -1)
    cv2.imwrite(img_path.split('.jpg')[0] + 'hv_flip.jpg', hv_flip)


# 直方图均衡-增加对比度
def equalizeHist(img_path):
    img = cv2.imread(img_path)

    b, g, r = cv2.split(img)

    b1 = cv2.equalizeHist(b)
    g1 = cv2.equalizeHist(g)
    r1 = cv2.equalizeHist(r)

    O = cv2.merge([b1, g1, r1])

    cv2.imwrite(img_path.split('.jpg')[0] + 'equalizeHist.jpg', O)




# 增加图像亮度
def add_clip(img_path):
    img = cv2.imread(img_path)
    img_t = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    h, s, v = cv2.split(img_t)

    # 增加图像亮度
    v1 = np.clip(cv2.add(1 * v, 30), 0, 255)
    cv2.imwrite(img_path.split('.jpg')[0] + 'add_clip.jpg', v1)


if __name__ == '__main__':
    flip('train/with_mask/with_mask13.jpg')
    add_clip('train/with_mask/with_mask13.jpg')
    equalizeHist('train/with_mask/with_mask13.jpg')
